﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;
using DataAccessLayer.DAL;


namespace BestBuy.SellerViews
{
    public partial class ManagerAdvertise : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataAccessLayer.User user = UserDAL.GetUserByUsername(HttpContext.Current.User.Identity.Name);
            if (user == null)
            {
                Response.Redirect("~");
            }
            if (!IsPostBack)
            {
                LoadAdvertiseProduct(user.ID);
            }
            
        }

        private void LoadAdvertiseProduct(int userID)
        {
            User user = SellerDAL.GetAdvertiseProduct(userID);
            gvAdvertiseProduct.DataSource = user.AdvertiseProducts;
            gvAdvertiseProduct.DataBind();
        }

        protected void gvAdvertiseProduct_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ProductCategory product = (ProductCategory)DataBinder.Eval(e.Row.DataItem, "ProductCategory");
                if (product != null)
                {
                    Label lbproduct = e.Row.FindControl("lbCategory") as Label;
                    if (lbproduct != null)
                    {
                        lbproduct.Text = product.Name;
                    }
                }
            }
        }
    }
}